var schoolBusListUrl = basePath + "/sys/report/schoolBus/list";

var dataGrid;
$(function() {
	loadData();
});

function loadData() {
	dataGrid = $('#notice').datagrid({
		url : schoolBusListUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			approvalStatus: $("#approvalStatus").val(),
			applyTimeQuery: $("#applyTimeQuery").val(),
			approvalTimeQuery: $("#approvalTimeQuery").val()
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [ 
			{
			field : 'id',
			width : 10,
			align : "center",
			checkbox : true
		},
		{ 
			field : 'depart',
			title : '部门',
			resizable : true,
			align : "center",
			width : 10
		}, 
		{
			field : 'useCarReason',
			title : '用车事由',
			width : 20,
			align : "center"
		}, 
		{
			field : 'number',
			title : '用车人数',
			width : 20,
			align : "center"
		}, 
		{
			field : 'destination',
			title : '目的地',
			width : 30,
			align : "center",
			editor:{type:'validatebox'}
		}, 
		{
			field : 'startTimeText',
			title : '开始时间',
			width : 15,
			align : "center"
		}, 
		{
			field : 'endTimeText',
			title : '结束时间',
			width : 15,
			align : "center"
		}, 
		{
			field : 'applyer',
			title : '申请人',
			width : 10,
			align : "center"
		}, 
		{
			field : 'applyTimeText',
			title : '申请时间',
			width : 20,
			align : "center"
		}, 
		{
			field : 'approver',
			title : '审批人',
			width : 10,
			align : "center"
		},
		{
			field : 'approvalTimeText',
			title : '审批时间',
			width : 20,
			align : "center"
		}, 
		{
			field : 'approvalStatusText',
			align : 'center',
			title : '审批状态',
			width : 20
        }, 
        {
			field : 'rejectReason',
			align : 'center',
			title : '驳回原因',
			width : 30
        }
        ]],
		onAfterEdit : function(rowIndex, rowData, changes){
			if(rowData.id){
				changes.id = rowData.id;
				changes.resourceRange = $("#resourceRange").val();
				addmodify(changes);
			}else {
				rowData.resourceRange = $("#resourceRange").val();
				addmodify(rowData);
			}
		}
	});
}

function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl); 
	$("#" + searchForm).submit();  
}

function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}
function resetForm(formId) {
	$("#" + formId)[0].reset();
	$("#applyStartDate").datebox('setValue', '');
	$("#applyEndDate").datebox('setValue', '');
}